package com.tianji.remark.task;

import com.tianji.remark.service.LikedRecordService;
import com.tianji.remark.service.impl.LikedRecordRedisServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
@RequiredArgsConstructor
public class LikedTimesCheckTask {

    private static final List<String> BIZ_TYPES = List.of("QA", "NOTE");// 业务类型
    private static final int MAX_BIZ_SIZE = 30;// 每次查询30个biz 防止一次性太多

    private final LikedRecordService likedRecordService;

    // 每20s执行一次，将redis中 业务类型 总点赞数 发送消息MQ
    @Scheduled(cron = "0/40 * * * * ?")
    public void checkLikedTimes() {
        for (String bizType : BIZ_TYPES) {
            likedRecordService.readLikedTimesAndSendMessage(bizType, MAX_BIZ_SIZE);
        }
    }
}
